<template>
    <div class="container" style="width:99%;margin-top:-25px;">
	<!-- 查询条件 -->
    <div class="query-box">
        <el-form :model="queryBox" status-icon ref="queryBox">
          <el-row>
            <el-col :span="4">
               <div class="depart-box">
                  <div class="slect-title">客户类型</div>
                  <el-select v-model="queryBox.type" clearable filterable>
                      <el-option
                          v-for="item in student_type_options"
                          :key="item.key"
                          :label="item.value"
                          :value="item.key">
                      </el-option>
                  </el-select>
                </div>
            </el-col>
            <el-col :span="4">
               <crm-perms-box perms="customer:student:source">
                <div class="depart-box">
                    <div class="slect-title">客户来源</div>
                    <el-select filterable v-model="queryBox.dataFrom" clearable placeholder="请选择" >
                        <el-option
                        v-for="item in student_data_from_options"
                        :key="item.key"
                        :label="item.value"
                        :value="item.key">
                        {{item.value}}
                        </el-option>
                    </el-select>
                  </div>
               </crm-perms-box>
            </el-col>

            <el-col :span="4">
              <div class="depart-box">
                  <div class="slect-title">客户进展</div>
                  <el-form-item @change="student_progress_change">
                    <el-select v-model="queryBox.progress" clearable placeholder="请选择">
                        <el-option
                        v-for="item in student_progress_options"
                        :key="item.key"
                        :label="item.value"
                        :value="item.key">
                        {{item.value}}
                        </el-option>
                    </el-select>
                  </el-form-item>
                </div>
            </el-col>
            <el-col :span="4">
               <el-form-item label="" prop="code">
                <el-input v-model="queryBox.code" placeholder="客户编号">
                    <template slot="prepend">客户编号</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
                <el-form-item label="" prop="name">
                <el-input  v-model="queryBox.name" placeholder="学生名称">
                    <template slot="prepend">学生名称</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
             
            
             <el-col :span="4">
               <el-form-item label="" prop="school">
                <el-input  v-model="queryBox.school" placeholder="学校名称">
                    <template slot="prepend">学校名称</template>
                </el-input>
              </el-form-item>
            </el-col>
             <el-col :span="4">
               <el-form-item label="" prop="providerTeacher">
                <el-input  v-model="queryBox.providerTeacher" placeholder="所属教师">
                    <template slot="prepend">所属教师</template>
                </el-input>
              </el-form-item>
               </el-col>
              <el-col :span="4">
                 <div class="depart-box">
                   <div class="slect-title">所属分中心</div>
                    <el-autocomplete
                      v-model="branchCenterName"
                      :fetch-suggestions="querySearchAsync"
                      placeholder="请输入内容"
                      @select="handleSelect"
                      
                    ></el-autocomplete>
                 </div> 
              </el-col>
              <el-col :span='4'>
                <div class="depart-box">
                   <div class="slect-title">所属销售</div>
                    <el-autocomplete
                      v-model="userName"
                      :fetch-suggestions="querySearchAsync2"
                      placeholder="请输入内容"
                      @select="handleSelect2"
                    ></el-autocomplete>
                 </div> 
              </el-col>
              <el-col :span="4">
                <div class="depart-box">
                  <el-form-item label prop="isTodayTracking">
                    <div class="depart-box">
                      <div class="slect-title">就读年级：</div>
                      <el-select
                        v-model="queryBox.grade"
                        placeholder="请选择"
                        :change="gradeChange"
                      >
                        <el-option
                          v-for="item in grade_cache_gradeOptions"
                          :key="item.value"
                          :label="item.fGradeName"
                          :value="item.fId"
                        ></el-option>
                      </el-select>
                    </div>
                  </el-form-item>
                </div>
              </el-col>
          </el-row>
          <el-row>
             <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">是否TMK</div>
              <el-select filterable clearable v-model="queryBox.isTmkContacted">
                <el-option
                  v-for="item in tmk_option"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </div>
          </el-col>
             <el-col :span='6'>
               <div class="depart-box">
                  <div class="slect-title">创建时间</div>
                   <el-date-picker
                      v-model="createDate"
                      type="daterange"
                      :start-placeholder="'开始时间'"
                      :end-placeholder="'结束时间'"
                      range-separator="至"
                      :default-time="['00:00:00', '23:59:59']"
                       value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss">
                    </el-date-picker>
                </div>
            </el-col>
            <el-col :span="12">
              <el-row class="area">
                <el-col :span="4">
                  <span class="city-title">所在地区：</span>
                </el-col>
                <el-col :span="8" style="margin-left:-1px">
                    <el-form-item label="" prop="area">                
                      <el-cascader
                      clearable
                      size="large"
                      :options="options"
                      v-model="selectedOptions"
                      >
                      </el-cascader>
                  </el-form-item>
                </el-col>
              </el-row>
          </el-col>
          </el-row>
        </el-form>
        <div class="from-btns">
            <kt-button :label="$t('action.reset')" perms="true" type="primary" @click="reset('queryBox')"/>
            <kt-button :label="$t('action.search')" perms="true" type="primary" @click="search"/>
        </div>
    </div>
  <!-- 批量删除按钮 -->
  <div class="add-btns fl">
    <kt-button :label="$t('action.batchdistribution')" :disabled="this.selections.length===0" 
    perms="customerdistribution:student:batchdistribution" type="primary" @click="handlebatchdistribution"/>
    
   <kt-button :label="$t('action.batchDelete')" perms="customerdistribution:student:delete" :size="size" type="danger" @click="handleBatchDelete" 
        :disabled="this.selections.length===0" style="float:left;"/>
  </div>
  <div class="fr">
    <kt-button :label="$t('action.download-tmpl')" type="primary" perms="customerdistribution:student:download" @click="downloadTmpl">
      
    </kt-button>
    <kt-button  :label="$t('action.batchimport')" type="primary" perms="customerdistribution:student:batchimport" @click="customerManagerImport"></kt-button>
    <kt-button :label="$t('action.add-user')" type="primary" perms="customerdistribution:student:add" @click="handleNewADD"></kt-button>
  </div>
	<!--表格内容栏-->
	<Crm-table  @selectionChange="selectionChange"  class="table-width" customerdistributionstu width="400"
    permsSee="customerdistribution:student:see"
    permsEdit="customerdistribution:student:edit"
		:data="pageResult" :columns="columns"
    :loading='loading'
		@findPage="findPage" @handleEdit="handleEdit"  @handleSee="handleSee">
	</Crm-table >
  
	<!--批量分配-->
  <div class="batchdistribution-pop">
        <el-dialog
                :visible.sync="batchdistribution"
                @close="$emit('update:batchdistribution', false)"
                 width="30%">
                <el-row>
                  <el-col :span="24">
                    <span class="batchdistribution-pop-tit">客户分配</span>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <span class="checked-person">已经选择{{selections.length}}位客户</span>
                  </el-col>
                </el-row>
                <el-form :inline="true" :model="addstuformData" class="demo-form-inline">
                  <el-row>
                      <el-col :span="24"  v-if="aa">
                        <el-row>
                          <el-col :span="6">
                            <span class="tit">人员选择：</span>
                          </el-col>
                          <el-col :span="18">
                              <el-select clearable  filterable  v-model="deptuseroptionValue" placeholder="请选择" @change="deptuserchange">
                                  <el-option
                                  v-for="item in users"
                                  :key="item.value"
                                  :label="item.realName"
                                  :value="item.id">
                                  </el-option>
                              </el-select>
                          </el-col>
                        </el-row>
                      </el-col>
                  </el-row>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="batchdistribution = false">取 消</el-button>
                    <el-button type="primary" v-if="aa" @click="batchdistributionsubmituser">确 定</el-button>
                </span>
            </el-dialog>
  </div>
    <!--导入-->
    <el-dialog :title="'批量导入'" width="30%" :visible.sync="uploadOem" :close-on-click-modal="false">
      <el-form :model="form" >
      <el-form-item >
        <el-upload
          ref="uploadExcel"
          :action=uploadUrl
          :limit=limitNum
          :auto-upload="false"
          accept=".xls"
          :before-upload="beforeUploadFile"
          :on-change="fileChange"
          :on-exceed="exceedFile"
          :on-success="handleSuccess"
          :on-error="handleError"
          :on-remove="handleRemove"
          :file-list="fileList">
          <el-button size="small"  plain>选择文件上传</el-button>
          <div slot="tip" class="el-upload__tip">只能上传xls(Excel97-2004)文件</div>
        </el-upload>
      </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="uploadOem = false">{{$t('action.cancel')}}</el-button>
        <el-button :size="size" type="primary" @click.native="uploadFile">{{$t('立即上传')}}</el-button>
      </div>
    </el-dialog>
  </div>
  
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import CrmTable from "@/views/Core/CrmTable";
import CrmSwitch from "@/views/Core/CrmSwitch";
import { CodeToText } from "element-china-area-data";
import { baseUrl } from '@/utils/global'
import CrmPermsBox from "@/views/Core/Crmpermsbox";
import { regionDataPlus } from 'element-china-area-data'
import axios from "axios";
import Cookies from "js-cookie"
export default {
  name: "Student",
  components: {
    PopupTreeInput,
    CrmTable,
    KtButton,
    CrmSwitch,
    CrmPermsBox
  },
  data() {
    return {
      aa: true,
      type:[],
      checkedPeson: 0,
      users:[],
      size: "small",
      // filters: {
      //   name: ""
      // },
      // 分中心名称
      restaurants: [],
      branchCenterName: '',
      userName:'',
      timeout:  null,
      // 查询条件
      student_data_from_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_type_options:[],
      student_progress_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_data_from_type_options: [
        {
          label: " ",
          key: " "
        }
      ],
      queryBox: {
        name: "",
        dataFrom: "",
        type: "",
        dataFromType: "",
        progress: "",
        code: "",
        phone: "",
        school: "",
        providerTeacher: "",
        providerAgent: "",
        createDate: "",
        moveDate: "",
        belongTo: "",
        pageNum:0,
        pageSize:0,
        importDepartment: "",
        grade:'',
        isTmkContacted:''
      },
      width: 200,
      columns: [
        { type:'index', label: "序号", minWidth: 50 },
        { prop: "createDate", label: "创建时间", minWidth: 140 },
        { prop: "name", label: "学生姓名", minWidth: 80 },
        { prop: "grade", label: "所在年级", minWidth: 120 },
        { prop: "school", label: "学校名称", minWidth: 120 },
        { prop: "laiyuan", label: "客户来源", minWidth: 100,id: "customerSource"},
        { prop: "type", label: "客户类型", minWidth: 100 },
        { prop: "TMK", label: "是否TMK", minWidth: 80 },
        { prop: "getprogress", label: "客户进展", minWidth: 70 }, 
        { prop: "diqu", label: "地区", minWidth: 190 },
        { prop: "areaInput", label: "详细地址", minWidth: 120 },
        { prop: "providerTeacher", label: "所属教师", minWidth: 100 },
        { prop: "providerAgent", label: "资源提供者", minWidth: 120 },
        { prop: "belongTo", label: "所属销售", minWidth: 120 },  
        { prop: "code", label: "客户编号", minWidth: 150 }
      ],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {
        content: []
      },
      operation: true, // true:新增, false:编辑
      batchdistribution: false, //显示批量分配弹窗
      customerownership: false, //显示客户归属弹窗
      uploadOem:false, //文件上传
      limitNum: 1, //上传最大个数
      form: {
        file: ''
      },
      fileList: [],
      uploadUrl:baseUrl+"/file/upload", //文件上传地址
      downloadTmplUrl:baseUrl+'/template/studentImportTemplate.xlsx',//模板下载地址
      selectionsLength: "",
      deptTreeProps: {
        label: "name",
        children: "children"
      },
      roles: [],
      selections: [], //选中列表集合
      ids: [], //分配ID集合
      ids2: [],
      deptData: [], //部门树
      deptTree: {
        label: "deptName",
        children: "children"
      },
      deptinputValue: "",
      // 划分方式
      deptmodeoptions: [
        {
          label: "分配至部门",
          value: "11"
        },
        {
          label: "分配至个人",
          value: "9"
        }
      ],
      deptmodeoptionsValue: "",
      submitID: "",
      deptId:  Cookies.get('threeLevelDeptId'),
      userID: "", //人员ID
      deptuseroption: [], //部门用户
      deptuseroptionValue: "",
      branchcenter: [], //分中心下拉
      branchcenterValue: "",
      branchcenterValueID: "",
      branchcenterCodeValue: "", //分中心编码
      addstuformData: {},
      deptLevel3:'',
      loading: false, // 加载标识
      createDate:'',
      //   地区
      options: regionDataPlus,
      selectedOptions: [],
      grade_cache_gradeOptions:[],
      roleId: "", //当前登录用户的角色id
      // roleId1: "307922416041209975", //咨询师
      // roleId2: "307922480151146627", //直销三级部门管理
      // roleId3: "307922544034590863", //直销部门管理
      // roleId4: "318843899038940998", //金丰和校区管理
      // roleId5: "318845886098849661", //金丰和班主任管理
      tmk_option:[
        {
          key: "1",
          value: "是"
        },
        {
          key: "2",
          value: "否"
        }
      ]
    };
  },
  methods: {
    // 搜索
    search() {
      this.loading=true
      this.queryBox.createDateStart=this.createDate[0]
      this.queryBox.createDateEnd=this.createDate[1]
      this.queryBox.province=this.selectedOptions[0]
      this.queryBox.city=this.selectedOptions[1]
      this.queryBox.area=this.selectedOptions[2]
      this.pageRequest.pageNum = 1;
      this.findPage(null)
    },
    // 获取分页数据
    findPage: function(data) {
      if (data !== null) {
        this.loading=true
        this.pageRequest = data.pageRequest;
      }
      this.queryBox.pageSize = this.pageRequest.pageSize;
      this.queryBox.pageNum = this.pageRequest.pageNum;
      this.$api.student
        .studentQueryCustomerAssign(this.queryBox)
        .then(res => {
          if(res.result==2){
            this.$message({
              message: res.msg,
              type: 'error'
            })
          }else{
            let content = {'content':res.listStudentInfo,'totalSize':res.total};
            this.pageResult=content;
            this.pageResult.content.forEach(item => {
              if(item.isTmkContacted==1){
                item.TMK='是'
              }else{
                item.TMK='否'
              }
             if(item.province==null&&item.city==null||item.province=='null'&&item.city=='null'){
                item.diqu=""
              }else{
                item.diqu = CodeToText[item.province] + CodeToText[item.city]+ CodeToText[item.area]+(item.areaInput==null?'':item.areaInput);
              }
              this.student_data_from_options.forEach(type_item=>{
                if(type_item.key==item.dataFrom){
                  item.laiyuan=type_item.value
                }
              })
              this.student_progress_options.forEach(progress_item=>{
                if(progress_item.key==item.progress){
                  item.getprogress=progress_item.value
                }
              })
              // 获取方式对应
              this.student_data_from_type_options.forEach(data_from_type_item=>{
                if(data_from_type_item.key==item.progress){
                  item.getType=data_from_type_item.value
                }
              }),
              // 客户类型
              this.student_type_options.forEach(type_item=>{
                if(type_item.key==item.type){
                        item.type=type_item.value
                    }
              }),
               //年级
              this.grade_cache_gradeOptions.forEach(gradeItem=>{
                if(gradeItem.fId== item.grade){
                  item.grade=gradeItem.fGradeName
                }
              })
             
            });
            this.loading=false
          }
        }) 
        .then(data != null ? data.callback : "");
    },
    // 加载用户角色信息
    // findUserRoles: function() {
    //   this.$api.role.findAll().then(res => {
    //     // 加载角色集合
    //     this.roles = res.data;
    //   });
    // },
    // 重置
    reset(queryBox) {
      this.$refs.queryBox.resetFields();
      this.queryBox.type=''
      this.queryBox.dataFrom=''
      this.queryBox.progress=''
      this.queryBox.providerAgent=''
      this.createDate=''
      this.queryBox.dataFromType=''
      this.queryBox.createDateStart=''
      this.queryBox.createDateEnd=''
      this.branchCenterName=''
      this.userName=''
      this.selectedOptions=[]
      this.queryBox.province=''
      this.queryBox.city=''
      this.queryBox.area=''
      this.queryBox.belongTo=''
      this.pageRequest.pageNum = 1;
      this.queryBox.grade=''
      this.queryBox.isTmkContacted=''
      this.findPage(null)
    },
    // 批量分配
    handlebatchdistribution(params) {
      this.batchdistribution = true;
      this.ids = [];
      let idstu = this.selections.map(item => item.id);
      // this.dataFormAdd = Object.assign({}, params.row);
      this.ids = idstu;
      this.deptuseroptionValue=''
      this.deptuseroption=''
    },
    // 批量分配提交
    batchdistributionsubmituser() {
      this.$api.user
        .studentAssign_customerManager({
          listStudentId: this.ids,
          belongType: 9,
          belongTo: this.userID,
          assignType: 3
        })
        .then(res => {
          if (res.result === 1) {
            this.$message({
              message: res.msg,
              type: "success"
            });
            this.batchdistribution = false;
            this.findPage(null)
          } else {
            this.$message({
              message: res.msg,
              type: "error"
            });
          }
        });
    },
    // 批量删除
    handleBatchDelete() {
      this.ids2 = [];
      let idstu2 = this.selections.map(item => item.id);
      // this.dataFormAdd = Object.assign({}, params.row);
      this.ids2 = idstu2;
      console.log(this.ids2);
      this.$confirm("确认删除"+this.selections.length+"个客户吗？", "提示", {}).then(() => {
        this.editLoading = true;
        this.$api.student.studentAssignResourceAssign({
            listStudentId: this.ids2,
            belongType: 13,
          })
          .then(res => {
            this.$message({ message:res.msg, type: "success" });
            this.findPage(null)
          });
      });
    },
    // 查看客户档案
    handleSee: function(params) {
       this.dataForm = Object.assign({}, params.row);
      // console.log(params.row)
      this.$router.push({
        path: "/Customerfile/Student",
        query: {
          id: this.dataForm.id
        }
      });
    },
    // 新增客户
    handleNewADD: function() {
      this.$router.push({
        path: "/Customerfile/AddStudent",
        query:{
          name:'customerAssignAdd'
        }
      });
    },
    selectionChange: function(params) {
      let selectionsLength = params.selections.length;
      this.selections = selections.selections;
    },
    // 获取选中的表格数据
    selectionChange: function(selections) {
      this.selections = selections.selections;
    },
    // 修改客户档案
    handleEdit: function(params) {
      this.dataForm = Object.assign({}, params.row);
      // console.log(params.row)
      this.$router.push({
        path: "/Customerfile/EditStudent",
        query: {
          id: this.dataForm.id
        }
      });
    },
    // 菜单树选中
    handleOptionClick() {},
    // 获取来源
    get_student_data_from() {
      this.student_data_from_options=JSON.parse(localStorage.getItem('studentSource'))
    },
    get_student_progress() {
      this.student_progress_options=JSON.parse(localStorage.getItem('studenProgress'))
    },
    student_progress_change(value) {
      this.queryBox.student_progressValue = value.toString();
    },
    // 获取三级部门数据
    get_dept_data() {
      this.$api.dropdown.deptLevel3({ deptType:1}).then(res => {
        this.deptData = res.departmentInfoList;
      });
    },
     //获取部门
    findDown: function () {
      this.$api.dropdown.deptLevel3().then(res =>{
        this.deptLevel3=res.departmentInfoList
      })
      // 获取人员
      this.$api.dropdown.users({userType:3}).then(res =>{
        this.Allusers=res.userInfoList
      })
    },
    // //三级部门下面员工集合
    findUsersDown:function (value) {
      // let threeId=JSON.parse(Cookies.get("threeLevelDeptId"))
      let threeId=Cookies.get("threeLevelDeptId")
      if(threeId=='null'){
        this.$api.dropdown.users({userType:3,accountStatus:1,isControlResource:1}).then(res =>{
          this.users=res.userInfoList
        })
      }else{
        this.$api.dropdown.users({userType:3,threeLevelDeptId:threeId,accountStatus:1,isControlResource: 1}).then(res =>{
          this.users=res.userInfoList
        })
      }
      // this.$api.dropdown.users({userType:3,threeLevelDeptId:this.deptId,accountStatus:1}).then(res =>{
      //   this.users=res.userInfoList
      // })
    },
    // // 获取部门用户
    // get_dept_user() {
    //   this.$api.student.queryUserList({ threeLevelDeptId: this.deptId }).then(res => {
    //     this.deptuseroption = res.userInfoList;
    //   });
    // },
    deptuserchange(value) {
      this.userID = value;
    },
    // 客户类型
    get_student_type() {
      this.student_type_options=JSON.parse(localStorage.getItem('stdentTpye'))
    },
    // 获取方式
    get_student_data_from_type(){
      this.student_data_from_type_options=JSON.parse(localStorage.getItem('stdentDataFromType'))
    },
    student_parent_type_change(value) {
      this.info.studentInfoDetail.studentInfoAttr.parentType = value.toString();
    },
    
    // 批量导入
    customerManagerImport:function(){
       this.uploadOem=true
       if(this.form.file!=''){
        this.$refs.uploadExcel.clearFiles()
        this.form.file=''
      } 
    },
    // 文件超出个数限制时的钩子
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: '警告',
        message: `只能选择 ${this.limitNum} 个文件，当前共选择了 ${files.length + fileList.length} 个`
      });
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      this.form.file = file.raw
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      let extension = file.name.substring(file.name.lastIndexOf('.')+1)
      let size = file.size / 1024 / 1024
      if(extension !== 'xls') {
        this.$notify.warning({
          title: '警告',
          message: `只能上传Excel97-2004（即后缀是.xls）的文件`
        });
      }
    },
    // 文件上传成功时的钩子
    handleSuccess(res, file, fileList) {
      this.form.file=''
      this.$refs.uploadExcel.clearFiles()
      this.$notify.success({
        title: '成功',
       message: `文件上传成功,数据处理中,稍后在我的消息中查看！`
      });

    },
    // 文件上传失败时的钩子
    handleError(err, file, fileList) {
      this.$notify.error({
        title: '错误',
        message: `文件上传失败`
      });
    },
    uploadFile() {
      let formData = new FormData()
      formData.append('file', this.form.file)
      axios.post(this.uploadUrl, formData, { "Content-Type": "multipart/form-data" }).then(res => {
        if (res.data.result == 1) {
          this.handleSuccess()
          let path=res.data.fileUrl
          console.log(path);
          this.$api.student.studentInfoCustomerAssignImport({path:path}).then(res => {
            // console.log(res);
            this.uploadOem=false
            this.findPage(null)
          })
        }
        else{
          this.handleError()
        }
      })
    },

    // 删除上传列表操作
    handleRemove(file, fileList) {
      this.form.file=''
    },
    // 下载模板
    downloadTmpl(){
      this.getStuTempl()
    },
    // 获取人员
    loadAllUser(){
      this.$api.dropdown.users({userType:3}).then(res =>{
        this.Allusers=res.userInfoList
      })
    },
    // 分中心远程搜索
    querySearchAsync(queryString, callback) {
      let restaurants = [{}];
      let results=''
      this.$api.dropdown.branchcenter().then(res => {
        for(let i of res.branchCenterInfoList){
              i.value = i.name;  //将想要展示的数据作为value
          }
        restaurants =res.branchCenterInfoList;
       results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        callback(results);
      })
    },
    createFilter(queryString) {
      return (restaurant) => {
          return (restaurant.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
    },
    handleSelect(item) {
      this.queryBox.providerAgent=item.id
    },
    // 销售人员远程搜索
    querySearchAsync2(queryString, callback) {
     let restaurants = [{}];
      let results = "";
      let threeId=JSON.parse(Cookies.get("threeLevelDeptId"))
      if(threeId==null){
        this.$api.dropdown.users({ userType: 3,deptType:1}).then(res => {
          for (let i of res.userInfoList) {
            i.value = i.realName; //将想要展示的数据作为value
          }
          restaurants = res.userInfoList;
          results = queryString
            ? restaurants.filter(this.createFilter2(queryString))
            : restaurants;
          callback(results);
        });
      }else{
        this.$api.dropdown.users({ userType: 3,deptType:1,threeLevelDeptId:this.deptId}).then(res => {
          for (let i of res.userInfoList) {
            i.value = i.realName; //将想要展示的数据作为value
          }
          restaurants = res.userInfoList;
          results = queryString
            ? restaurants.filter(this.createFilter2(queryString))
            : restaurants;
          callback(results);
        });
      }
    },
    createFilter2(queryString) {
      return (restaurant) => {
          return (restaurant.realName.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
    },
    handleSelect2(item) {
      this.queryBox.belongTo=item.id
    },
    // 获取销售姓名
    get_sale_name(){
      this.$api.dropdown.users({ userType: 3 }).then(res => {
        this.belongTo = res.userInfoList;
      });
    },
    // 获取年级
    get_grade_cache() {
       this.grade_cache_gradeOptions=JSON.parse(localStorage.getItem('gradeCache'))
    },
     gradeChange(item){
      this.queryBox.grade = item.fId;
    },
    // 查询角色信息
    queryUserRole() {
      this.$api.role.queryUserRole().then(res => {
        if (res.result == 1) {
          this.roleId = res.userInfo.roleId;
          if (
            this.roleId == this.roleId1 ||
            this.roleId == this.roleId2 ||
            this.roleId == this.roleId3 ||
            this.roleId == this.roleId4 ||
            this.roleId == this.roleId5
          ) {
            this.columns.map(item => {
              if (item.id) {
                item.customerSource = "customerSource";
              }
            });
          }
        }
      });
    }  
  },
  mounted() {
    this.get_student_data_from();
    this.get_student_progress();
    this.get_dept_data();
    this.get_student_type()
    this.get_student_data_from_type()
    this.get_sale_name()
    this.get_grade_cache()
    this.findUsersDown()
     this.queryUserRole();
  }
};
</script>
<style >
@import url("../../assets/queryBox.css");
</style>
<style lang='scss' scoped>
.checked-person {
  font-weight: 500;
  display: inline-block;
  text-align: center;
  margin: 3% 0 3% 0;
}
.batchdistribution-pop-tit{
  font-size: 20px;
  font-weight: bold;
  display: inline-block;
  color: #303133;
}
.demo-form-inline{
  width: 90%;
  margin: 0 auto;
  .el-dialog__body .el-input{
    width: 93% !important;
  }
  .el-select{
    width: 100% !important;
  }
  .tit{
    display: inline-block;
    margin-top: 10%;
  }
}
.batchdistribution-pop .el-row .el-col {
  margin-left: 0;
}
.el-dialog__wrapper .el-form-item__content{
  margin-left: 0 !important;
}
</style>
<style lang='scss'>
.batchdistribution-pop .el-dialog__header{
  padding: 0 0 0 0 !important;
}
</style>


